package com.example.thread.base.a1b2c3;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2021/6/28 12:20
 * @Description wait/notify
 */
public class Print_WaitAndNotify {
    public static void main(String[] args) {
        final Object o = new Object();
        char[] aI="1234567".toCharArray();
        char[] aC="ABCDEFG".toCharArray();
        new Thread(()->{
            synchronized (o){
                for (char c : aC){
                    try {
                        System.out.println(c);
                        o.wait();
                        o.notify();
                    }catch (Exception e ){
                        e.printStackTrace();
                    }
                }
            }
        },"t1").start();
        new Thread(()->{
            synchronized (o){
                for (char c :aI) {
                    System.out.println(c);
                    o.notify();
                    try{
                        o.wait();
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
                o.notify();
            }
        },"t1").start();

    }
}
